package com.tz.marlon.web.blog;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.tz.marlon.bean.TzParams;
import com.tz.marlon.dao.blog.IBlogDao;

@Controller
@RequestMapping("/blog")
public class BlogController {
	
	@Autowired
	private IBlogDao blogDao;
	
	/**
	 * 页面初始化加载
	 * 方法名：index<BR>
	 * 创建人：Marlon <BR>
	 * 时间：2016年5月10日-下午5:23:32 <BR>
	 * @param params
	 * @return ModelAndView<BR>
	 * @exception <BR>
	 * @since  1.0.0
	 */
	@RequestMapping("/index")
	public String index(){
		return "/blog/index";
	}
	
	@RequestMapping("/detail/{id}")
	public ModelAndView detail(@PathVariable("id")Integer id){
		ModelAndView modelAndView = new ModelAndView();
		HashMap<String, Object> blog = blogDao.mapById(id);
		modelAndView.setViewName("blog/detail");
		modelAndView.addObject("blog",blog);
		return modelAndView;
	}
	/**
	 * 加载更多数据
	 * 方法名：loadDate<BR>
	 * 创建人：Marlon <BR>
	 * 时间：2016年5月10日-下午5:23:12 <BR>
	 * @param params
	 * @return List<HashMap<String,Object>><BR>
	 * @exception <BR>
	 * @since  1.0.0
	 */
	@ResponseBody
	@RequestMapping(method=RequestMethod.POST,value="/loadData")
	public List<HashMap<String, Object>> loadDate(TzParams params){
		params.setStatus(1);
		params.setIsDelete(1);
		params.setIsTop(0);
		List<HashMap<String, Object>> blogs = blogDao.listMaps(params);
		return blogs;
	}
	
	/**
	 * 
	 * 方法名：loadTop<BR>
	 * 创建人：Marlon <BR>
	 * 时间：2016年5月31日-下午1:47:12 <BR>
	 * @param params
	 * @return List<HashMap<String,Object>><BR>
	 * @exception <BR>
	 * @since  1.0.0
	 */
	@ResponseBody
	@RequestMapping(method=RequestMethod.POST,value="/loadTop")
	public List<HashMap<String, Object>> loadTop(TzParams params){
		params.setStatus(1);
		params.setIsDelete(1);
		params.setIsTop(1);;
		List<HashMap<String, Object>> blogs = blogDao.listMaps(params);
		return blogs;
	}
	
	@ResponseBody
	@RequestMapping(method=RequestMethod.POST,value="/relation")
	public List<HashMap<String, Object>> relation(TzParams params){
		params.setPageSize(4);
		params.setStatus(1);
		params.setIsDelete(1);
		List<HashMap<String, Object>> relations = blogDao.listMaps(params);
		return relations;
	}
	
}
